/** 动态加载业务自定义选人页签的js
 * @param { String } url 加载js地址
 * @param { String } key 自定义页签唯一标识
 */
export function loadScript(url, key) {
	let keys = [];
	return new Promise((resolve, reject) => {
		if (keys.includes(key)) {
			resolve();
			return;
		}
		let script = document.createElement('script');
		script.type = 'text/javascript';
		script.async = true;
		script.src = url;
		script.onerror = reject;
		script.onload = function () {
			keys.push(key);
			resolve();
		};
		document.body.appendChild(script);
	});
}

/** 动态加载业务自定义选人页签的css
 * @param { String } url 加载js地址
 * @param { String } key 自定义页签唯一标识
 */
export function loadStyle(url, key) {
	let keys = [];
	return new Promise(resolve => {
		if (keys.includes(key)) {
			resolve();
			return;
		}
		let link = document.createElement('link');
		link.rel = 'stylesheet';
		link.type = 'text/css';
		link.href = url;
		keys.push(key);
		document.head.appendChild(link);
		resolve();
	});
}
